package itd.newbee.mall.newbeemall.controller;

import itd.newbee.mall.newbeemall.entity.SaleGoods;
import jakarta.el.TypeConverter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2025/3/5 11:26
 */
@RestController

public class TestController {
    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }

    //    测试类型转换
    @RequestMapping("/test/type/conversion")
    public void testTypeConversion(String goodsName, float price, int type, boolean onSale) {
        System.out.println("goodsName=" + goodsName);
        System.out.println("price=" + price);
        System.out.println("type=" + type);
        System.out.println("onSale=" + onSale);

        //http://localhost:8080/test/type/conversion?goodsName=%E9%A6%92%E5%A4%B4&price=1.00&type=1&onsale=ture
//        http://localhost:8080/test/type/conversion?goodsName=%E9%A6%92%E5%A4%B4&price=1.00&type=1&onsale=1
    }
    @RequestMapping(value = "/test/httpmessageconverter",method = RequestMethod.POST)
    public SaleGoods httpMessageConverterTest(@RequestBody SaleGoods saleGoods) {
        System.out.println(saleGoods.getGoodsName());
        saleGoods.setType(saleGoods.getType() + 1);
        saleGoods.setGoodsName("商品名:" + saleGoods.getGoodsName());
        return saleGoods;
    }
}
